import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from "path";
import vueJsx from '@vitejs/plugin-vue-jsx';
import { Plugin as importToCDN, autoComplete } from 'vite-plugin-cdn-import';

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        vueJsx(),
        importToCDN({
            modules: [
                autoComplete('vue'),
                {
                    name: 'vue',
                    var: 'Vue',
                    path: 'https://unpkg.com/vue@3.2.33/dist/vue.global.prod.js',
                },
                {
                    name: 'vue-demi',
                    var: 'VueDemi',
                    path: 'https://unpkg.com/vue-demi@0.13.2/lib/index.iife.js',
                },
                // {
                //     name: 'vue-router',
                //     var: 'VueRouter',
                //     path: 'https://unpkg.com/vue-router@4.0.16/dist/vue-router.global.prod.js',
                // },
                {
                    name: 'element-plus',
                    var: 'ElementPlus',
                    path: `https://unpkg.com/element-plus@2.2.8/dist/index.full.min.js`,
                    css: 'https://unpkg.com/element-plus@2.2.8/dist/index.css',
                },
                {
                    name: 'pinia',
                    var: 'Pinia',
                    path: 'https://unpkg.com/pinia@2.0.13/dist/pinia.iife.prod.js',
                },
            ],
        }),
    ],
    server: {
        host: "0.0.0.0", // 解决 vite use '--host' to expose 问题
        port: 666,
        open: true,
    },
    resolve: {
        alias: [
            {
                find: "@", // 配置路径别名
                replacement: resolve(__dirname, "src"),
            },
        ],
    },
})
